/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.zhy.math;

/**
 *
 * @author Moon
 */
public class LineSegment {

    private Point point0;
    private Point point1;

    public LineSegment(double x0, double y0, double x1, double y1) {
        this.point0 = new Point(x0, y0);
        this.point1 = new Point(x1, y1);
    }

    public Point getPoint0() {
        return point0;
    }

    public void setPoint0(Point point0) {
        this.point0 = point0;
    }

    public Point getPoint1() {
        return point1;
    }

    public void setPoint1(Point point1) {
        this.point1 = point1;
    }

    public Line getLine() {
        double x0 = point0.getX();
        double y0 = point0.getY();
        double x1 = point1.getX();
        double y1 = point1.getY();
        double a = y1 - y0;
        double b = x0 - x1;
        if (a == 0 && b == 0) {
            throw new IllegalArgumentException("(x0,y0) is same with (x1,y1)");
        }
        double c = x1 * y0 - x0 * y1;
        return new Line(a, b, c);
    }

    public double getX0() {
        return point0.getX();
    }

    public double getX1() {
        return point1.getX();
    }

    public double getY0() {
        return point0.getY();
    }

    public double getY1() {
        return point1.getY();
    }
}
